<% user_team_ids = @user.team_ids
   org = current_user.organization
   manages_admins = manages_admins?
   is_admin = is_admin? %>
<div class="modal-header">
  <button class="close" data-dismiss="modal">&times;</button>
  <h3><%= @user.username %></h3>
</div>
<%= form_tag(organization_user_url(@user), :method => :put, :remote => true, :class => 'form-inline') do %>
  <div class="modal-body">
    <h5>Team Membership</h5>
    <% org.teams.order(:name).each do |team| %>
      <label>
        <% admin_user = user_team_ids.include?(team.id)
           editable = team.name == Team::ADMINS && !admin_user ? manages_admins : is_admin %>
        <a class="btn <%= 'disabled' unless editable %>">
          <% if editable %>
            <%= check_box_tag('teams[]', team.id, admin_user)  %>
          <% else %>
            <%=  hidden_field_tag 'teams[]', team.id  %>
          <% end %>
          <%= team.name %>
        </a>
      </label>
    <% end %>
  </div>
  <% if is_admin %>
    <div class="modal-footer">
      <button class="btn btn-danger btn-large" data-dismiss="modal">Cancel</button>
      <%= submit_tag 'Save', :class => 'btn btn-success btn-large' %>
    </div>
  <% end %>
<% end %>
